package com.itheima.health.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

@SuppressWarnings("ALL")
/**
 * @Description ：检查项controller
 * @author     :LD
 */
@RestController
@RequestMapping("checkItem")
@Api(tags = "预约模块-检查项管理")
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询检查项", notes = "获取所有的检查项信息")
    public Result findAll() {
        List<CheckItem> list = checkItemService.findAll();
        return new Result(list);
    }

    @PostMapping("findPage")
    @ApiOperation(value = "分页查询检查项",notes = "根据条件分页查询")
    @ApiImplicitParam(name = "queryPageBean",value = "分页条件封装类",required = true,dataType = "QueryPageBean")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        Map map = checkItemService.findPageCondition(queryPageBean);
        return new Result(map);
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "删除检查项",notes = "根据id逻辑删除检查项")
    @ApiImplicitParam(name = "id",value = "检查项id",paramType = "path",dataType = "Integer")
    public Result deleteBuId(@PathVariable("id")Integer id){
        CheckItem checkItem = new CheckItem();
        checkItem.setId(id);
        checkItem.setIs_delete(1);
        checkItemService.updateById(checkItem);
        return new Result(true);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加检查项",notes = "添加检查项")
    @ApiImplicitParam(name = "checkItem",value = "检查项信息",required = true,dataType = "CheckItem")
    public Result save(@RequestBody CheckItem checkItem){
        checkItemService.save(checkItem);
        return new Result(true);
    }

    @PutMapping("edit")
    @ApiOperation(value = "修改检查项",notes = "修改检查项")
    @ApiImplicitParam(name = "checkItem",value = "检查项信息",required = true,dataType = "CheckItem")
    public Result edit(@RequestBody CheckItem checkItem){
        checkItemService.updateById(checkItem);
        return new Result(true);
    }
}
